package com.lovo.boot.model.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.lovo.boot.enums.ResultCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @title
 * @author: luo
 * @date: 2020/11/17 16:57
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVO implements Serializable {

    private Boolean success;
    private Integer status;
    private String message;
    private Object data;
    public ResultVO(ResultCode resultCode, Object data){
        this.status = resultCode.status();
        this.message = resultCode.message();
        this.data = data;
    }
    public ResultVO(ResultCode resultCode){
        this.status = resultCode.status();
        this.message = resultCode.message();
    }

    // 返回成功
    public static ResultVO success(){
        ResultVO resultVO = new ResultVO(ResultCode.SUCCESS);
        resultVO.setSuccess(true);
        return resultVO;
    }
    // 返回成功
    public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO(ResultCode.SUCCESS,data);
        resultVO.setSuccess(true);
        return resultVO;
    }
    // 返回失败
    public static ResultVO fail(ResultCode resultCode){
        ResultVO resultVO = new ResultVO(resultCode);
        resultVO.setSuccess(false);
        return resultVO;
    }
    // 返回失败
    public static ResultVO fail(ResultCode resultCode, Object data){
        ResultVO resultVO = new ResultVO(resultCode,data);
        resultVO.setSuccess(false);
        return resultVO;
    }



}
